import DialogForm from '@/utils/tools/DialogForm'
import { savebsCardImage, editbsCardImage, getByIdbsCardImageById, deletebsCardImage } from '@/apiList/api_power'

// 用户管理
export default class Dialog extends DialogForm {
  paramsFormat(formData) {
    return {
      ...formData
    }
  }
  // 新增提交 - 1
  async addSubmit(formData) {
    const params = this.paramsFormat(formData)

    await savebsCardImage(params.userInfo)
  }
  // 编辑打开弹窗
  async editOpenDialog(row) {
    let res = await this.getByIdInfo(row)
    await this.addOpenDialog()
    this.submitType = 1
    this.setData({
      addFormData: {
        userInfo: res
      }
    })
  }
  // 编辑提交 - 2
  async editSubmit(row) {
    const params = this.paramsFormat(this.data.addFormData.userInfo)
    await editbsCardImage({ id: row.id, ...params })
  }
  // 表单验证 - 3
  async fromDataVali(data) {
    const f = data.userInfo
   
    if (!f.title) return this.$alert('请输入工程案例名称')

    return true
  }
  // 删除提交 - 4
  async delSubmit(rowList) {
    let ids = rowList.map((e) => e.id).toString()
    await deletebsCardImage({ id: ids })
  }
  // 更新列表 - 5
  async updateList() {
    this.data.getList() // 调用父级列表更新
  }
  // 通过id获取详情 - 6
  async getByIdInfo(id) {
    let res = await getByIdbsCardImageById({ id: id })
    return res
  }
}
